define(['app'], function(app) {
    app.controller('statisticbymCtrl', function($scope, $http) {

        $scope.year = false ;
        $scope.month = false ;

        layui.use('laydate', function(){
            var laydate = layui.laydate;
            laydate.render({
                elem: '#test3',
                type: 'month',
                theme: '#1E9FFF',
                btns: ['clear','now','confirm'],
                ready:function(date){
                    //弹出窗口触发
                    console.log(date)
                    $scope.year = date.year ;
                    $scope.month = date.month ;
                },
                change:function(value, date, endDate){
                    //点击具体日期/月份触发
                    console.log(date)
                    $scope.year = date.year ;
                    $scope.month = date.month ;
                }
            });
        })
        $scope.query = function(){
            console.log($scope.year, $scope.month)

            if(!$scope.year || !$scope.month){
                return layer.confirm('请先选择时间', {
                    icon: 0,
                    btn: ['知道了'],
                    title: '提示'
                }, function(index) {
                    layer.close(index);
                });

            }
            $http({
                method:'post',
                url:'/OSRS/statistics/month',
                data:$scope.year+"-"+$scope.month
            }).then(function(res){
                console.log(res)
                $scope.title = "天智教育（苏州）学员评教"+ $scope.year + ' 年 ' +$scope.month + ' 月 统计表'
                $scope.datas =res.data;

            },function(err){
                console.log(err)

                return layer.msg('数据获取失败~');
            })

        }
    });

});
